<template>
	<view class="" >
		<view class="content" v-if="!isEntry" style="padding-bottom: 150rpx;">
			<view style="height: 30rpx"></view>
			<view class="qiYe" v-for="item in recruitList" :key="item.id" @click="toXq(item.id)">
				<view v-if="item">
					<view class="title">{{ item.name }}</view>
					<view class="name">{{ item.name }}</view>
				</view>
				<view v-if="item">
					<image :src="pic + item.logo" mode="scaleToFill" />
				</view>
			</view>
			<u-empty v-if="recruitList.length == 0 && !isEntry" mode="list"
				icon="http://cdn.uviewui.com/uview/empty/list.png" />
		</view>
		<view class="isEntry" v-if="isEntry">
			<image :src="configInfo.zp_image" style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;" mode=""></image>
		</view>
		<tabbar :current="1" ref="tabbarRef"></tabbar>
	</view>
</template>

<script>
	import yTag from "@/components/y-tag/index";
	export default {
		name: "tab-1",
		components: {
			yTag,
		},
		data() {
			return {
				recruitList: [],
				pic: this.$IMG_URL,
				user_sn: "", //只有当用户入职后user_sn才有值，否则为null或""
				isEntry: false, //是否入职
				groupId: 0,
				configInfo: {},
				is_lz: 0, //0未离职,1离职
				is_sqzp: 0,
			};
		},
		onLoad() {
			uni.hideTabBar()
		},
		onShow() {
			this.$nextTick(function() {
				this.$refs.tabbarRef.$emit("childmethod")
			});
			this.getUserAuth();
			this.getConfigInfo();
		},
		methods: {
			async getConfigInfo() {
				const data = await this.http.get("index/getConfigInfo");
				this.configInfo = data.data
				this.tabbarRedirection();
			},
			tabbarRedirection(user_sn = "", groupId) {
				console.log('====', groupId);
				if ((this.configInfo.is_zpshowstatus == 2 && this.is_lz == 1) || this.configInfo.is_zpshowstatus == 0 ||
					this.is_sqzp == 1) {
					this.isEntry = false;
					this.getRecruitList()
				} else {
					uni.setTabBarItem({
						index: 1,
						text: '企业招聘',
					});
					uni.setNavigationBarTitle({
						title: '企业招聘'
					})
					this.recruitList = [];
					this.isEntry = true;
					return;
				}
				//此功能函数用于如果员工已经入职则不显示招聘模块
				//   	if(user_sn != null && user_sn != ""){
				// 	if (groupId == 1 || groupId == 2) { //驻场、文员
				// 		this.isEntry = false;
				// 	} else{
				// 		console.log("设置tabbar----");
				// 		console.log(user_sn)
				// 		uni.setTabBarItem({
				// 		  index: 1,
				// 		  text: '暂无权限',
				// 		});
				// 		uni.setNavigationBarTitle({
				// 			title:'暂无权限'
				// 		})
				// 		this.recruitList = [];	
				// 		this.isEntry = true;
				// 		return;
				// 	}
				//   	} else {
				// 	this.isEntry = false;
				// }

				// this.getRecruitList();
			},
			async getUserAuth() {
				//获取userSn判断用户是否入职
				if (!uni.getStorageSync("token")) return;
				const data = await this.http.get("user/getUerInfo");
				this.user_sn = data.data.user_sn;
				this.is_lz = data.data.is_lz
				this.is_sqzp = data.data.is_sqzp
				if (data.data.group_id == 2) {
					this.groupId = 2;
				} else if (data.data.group_id == 3) {
					this.groupId = 1;
				}


			},
			async getRecruitList() {
				//获取公司列表
				const data = await this.http.get("recruit/companys");
				this.recruitList = data.data;
			},
			toXq(id) {
				// is_zpshowstatus 0全部显示 1隐藏 2离职人员显示
				if ((this.configInfo.is_zpshowstatus == 2 && this.is_lz == 1) || this.configInfo.is_zpshowstatus == 0 ||
					this.is_sqzp == 1) {
					uni.navigateTo({
						url: "/pages/tab2/zhaPin?id=" + id,
					});
				} else {
					console.log(this.configInfo.is_zpshowstatus, "asdgh");
					uni.navigateTo({
						url: "/pages/tab2/tupian"
					});
				}
			},
		},
	};
</script>
<style lang="scss" scoped>
	// .isEntry {
	// 	font-size: 70rpx;
	// 	position: absolute;
	// 	top: 35%;
	// 	left: 50%;
	// 	text-align: center;
	// 	transform: translateX(-50%);
	// 	font-weight: 800;
	// 	color: gray;
	// }

	.qiYe {
		padding: 20rpx;
		display: flex;
		border-radius: 20rpx;
		justify-content: space-between;
		background-image: linear-gradient(to right, #87aef6, #6190f7);
		margin: 0 25rpx;
		align-items: center;
		color: white;
		margin-bottom: 20rpx;

		image {
			width: 150rpx;
			height: 150rpx;
			border-radius: 20rpx;
		}

		.title {
			font-size: 32rpx;
			margin-bottom: 20rpx;
		}

		.name {
			font-size: 24rpx;
		}
	}
</style>